package com.sairobo.base.common.support;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.springframework.web.util.HtmlUtils;

import java.io.IOException;

/**
 * html标签反转义
 */
public class HtmlUnEscapeDeSerializer extends JsonDeserializer<String> {

    @Override
    public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        String str = jp.getText();
        return HtmlUtils.htmlUnescape(str);
    }


    public static void main(String[] args) {
        String a = "<h1 class=\"class-summary-title\" style=\"outline: none;>";
        System.out.println(HtmlUtils.htmlEscape(a));
        System.out.println(HtmlUtils.htmlUnescape(HtmlUtils.htmlEscape(a)));
    }
}
